package cn.xorange.commons.system.mapper.platform;

import cn.xorange.commons.data.core.mapper.MBaseMapper;
import cn.xorange.commons.system.entity.platform.SysAgreement;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author : yangjian
 * date : 2022/1/28
 */
@Mapper
public interface SysAgreementMapper extends MBaseMapper<SysAgreement> {

    @Select("select agreement_id,(case when update_time is null then create_time else update_time end) as update_time from sys_agreement where type = #{type}")
    List<SysAgreement> selectAgreementIdList(@Param("type") String type, @Param("module") String module);

    @Update("update orange_user set service_time = (case when service_time< #{serviceTime} then sysdate() else service_time end)  ,privacy_time = (case when privacy_time< #{privacyTime} then sysdate() else privacy_time end) where user_id = #{userId}")
    int updateOrangeUserAgreementTime(@Param("userId") Long userId, @Param("serviceTime") Date serviceTime, @Param("privacyTime") Date privacyTime);

    @Update("insert log_agreement(user_id,agreement_id,sign_time) values (#{userId},#{agreementId},#{signTime})")
    int InsertSysAgreementLog(@Param("userId") Long userId,@Param("agreementId") Long agreementId,@Param("signTime") Date signTime);
}
